package gui.frames;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.JButton;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerNumberModel;

public class GuiDomainSettings extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private GuiMain gm;

	/**
	 * This is the default constructor
	 */
	public GuiDomainSettings(GuiMain g) {
		super();
		gm = g;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(400, 290);
		this.setContentPane(getJContentPane());
		this.setTitle("Domain Settings Manager");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			
			JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
			jContentPane.add(tabbedPane, BorderLayout.CENTER);
			
			JPanel panel = new JPanel();
			panel.setLayout(new BorderLayout());
			tabbedPane.addTab("Anisotropy", null, panel, "Allows to edit anisotropy layers");
			
			JPanel panel_2 = new JPanel();
			panel_2.setLayout(new BorderLayout());
			panel.add(panel_2, BorderLayout.NORTH);
			
			
			JPanel panel_3 = new JPanel();
			panel.add(panel_3, BorderLayout.CENTER);
			panel_3.setLayout(null);
			
			final JLabel lblStep = new JLabel("step:");
			lblStep.setBounds(10, 11, 46, 14);
			panel_3.add(lblStep);
			
			SpinnerNumberModel model = new SpinnerNumberModel(gm._step, 1, 50, 5); 
			final JSpinner spinner = new JSpinner(model);
			
			spinner.setBounds(74, 8, 58, 20);
			panel_3.add(spinner);
			
			final JLabel lblDegree = new JLabel("degree:");
			lblDegree.setBounds(10, 42, 46, 14);
			panel_3.add(lblDegree); 
			lblDegree.setVisible(false);
			
			SpinnerNumberModel model1 = new SpinnerNumberModel((int) gm._degree, 0, 360, 1);
			final JSpinner spinner_1 = new JSpinner(model1);
			spinner_1.setBounds(74, 39, 58, 20);
			spinner_1.setVisible(false);
			panel_3.add(spinner_1);
			
			JPanel panel_1 = new JPanel();
			tabbedPane.addTab("View", null, panel_1, "Allows to edit domain view");
			
			JPanel panel_4 = new JPanel();
			jContentPane.add(panel_4, BorderLayout.SOUTH);
			
			
			String[] strCombo = {"Dotted Anisotropy", "Cell Anisotropy", "Linar Anisotropy"};
			final JComboBox comboBox = new JComboBox(strCombo);
			panel_2.add(comboBox, BorderLayout.NORTH);
			comboBox.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if (comboBox.getSelectedIndex() ==  2){
						lblDegree.setVisible(true);
						spinner_1.setVisible(true);
						spinner.setVisible(false);
						lblStep.setVisible(false);
					}
					else{
						lblDegree.setVisible(false);
						spinner_1.setVisible(false);
						spinner.setVisible(true);
						lblStep.setVisible(true);
					}
				}
			});
			
			
			JButton btnNewButton = new JButton("OK");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					gm._step = (int) spinner.getValue();
					gm._degree = (int) spinner_1.getValue();
					dispose();
				}
			});
			panel_4.add(btnNewButton);
			
			JButton btnCancel = new JButton("Cancel");
			btnCancel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					dispose();
				}
			});
			panel_4.add(btnCancel);
			
			tabbedPane.setEnabledAt(1, false);
		}
		return jContentPane;
	}
}
